package ants;

import ants.bot.Bot;
import ants.map.AntsMap;

public final class Ants extends AbstractSystemInputParser {

	private final Bot bot;
	private final AntsMap gameMap;
	private int loadTime;
	private long turnStartTime;
	private int turnTime;

	public Ants(Bot bot, AntsMap gameMap) {
		super();
		this.bot = bot;
		this.gameMap = gameMap;
	}

	@Override
	public void addAnt(int row, int col, int owner) {
		gameMap.addAnt(row, col, owner);
	}

	@Override
	public void addFood(int row, int col) {
		gameMap.addFood(row, col);
	}

	@Override
	public void addHill(int row, int col, int owner) {
		gameMap.addHill(row, col, owner);
	}

	@Override
	public void addWater(int row, int col) {
		gameMap.addWater(row, col);
	}

	@Override
	public void afterUpdate() {
		gameMap.update();
	}

	@Override
	public void beforeSetup() {
		turnStartTime = System.currentTimeMillis();
		gameMap.reset();
	}

	@Override
	public void beforeUpdate() {
		turnStartTime = System.currentTimeMillis();
		gameMap.reset();
	}

	@Override
	public void doTurn() {
		bot.doTurn();
	}

	public int getTurn() {
		return turn;
	}

	public long getTurnStarttime() {
		return turnStartTime;
	}

	public int getTurntime() {
		if (turn == 0)
			return loadTime;
		else
			return turnTime;
	}

	@Override
	public void removeAnt(int row, int col, int owner) {
		gameMap.removeAnt(row, col, owner);
	}

	@Override
	public void setup(int loadTime, int turnTime, int rows, int cols, int turns,
			int viewRadius2, int attackRadius2, int spawnRadius2) {
		gameMap.initialize(rows, cols, viewRadius2, attackRadius2);
		gameMap.reset();
		gameMap.update();
		this.loadTime = loadTime;
		this.turnTime = turnTime;
	}

}
